<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
	<style type="text/css">
	body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=rkKeu7GnzIuWK2cgYTAtKko7O0UZRLZy"></script>
	<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
        <title>地图定位</title>
</head>
<body>
	<div id="allmap"></div>
</body>

<script type="text/javascript">
    function getLocation()
      {
      if (navigator.geolocation)
        {
            navigator.geolocation.getCurrentPosition(showPosition,showError);
        }
      else{alert("不支持浏览器");}
      }
      
      function showPosition(position)
      {

        alert("yes");
          
//         var map = new BMap.Map("allmap");
//         var point = new BMap.Point(116.331398,39.897445);
//         map.centerAndZoom(point,12);
//         var geoc = new BMap.Geocoder();
//         var obj = new BMap.Point(position.coords.longitude, position.coords.latitude);
        
//         geoc.getLocation(obj, function(rs){
//                     var addComp = rs.addressComponents;
//                     var store = window.localStorage;
//                     var user_address = (addComp.city+ addComp.district + addComp.street + addComp.streetNumber);
//                     store.setItem('service_address',user_address);

// //			alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
// //                    $("#myaddress").text(addComp.city  + addComp.district  + addComp.street  + addComp.streetNumber);
                    
                    
//             }); 
	
      }
    function showError(error)
      {
      switch(error.code) 
        {
        case error.PERMISSION_DENIED:
            alert("用户拒绝共享地址");
//          x.innerHTML="User denied the request for Geolocation."
          break;
        case error.POSITION_UNAVAILABLE:
            alert("获取出错1");
//          x.innerHTML="Location information is unavailable."
          break;
        case error.TIMEOUT:
            alert("获取超时出错");
//          x.innerHTML="The request to get user location timed out."
          break;
        case error.UNKNOWN_ERROR:
            alert("获取出错2");
//          x.innerHTML="An unknown error occurred."
          break;
        }
      }
      
	// 百度地图API功能
	var map = new BMap.Map("allmap");
        
	var point = new BMap.Point(113.942972,22.540738);
	map.centerAndZoom(point, 15);
	var marker = new BMap.Marker(point);  // 创建标注
	map.addOverlay(marker);               // 将标注添加到地图中
	// marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

//        var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
//	var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
//	var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); //右上角，仅包含平移和缩放按钮
//	/*缩放控件type有四种类型:
//	BMAP_NAVIGATION_CONTROL_SMALL：仅包含平移和缩放按钮；BMAP_NAVIGATION_CONTROL_PAN:仅包含平移按钮；BMAP_NAVIGATION_CONTROL_ZOOM：仅包含缩放按钮*/
//	map.addControl(top_left_control);        
//        map.addControl(top_left_navigation);
	
</script>
</html>